/*
 * @Description: 定义表示记分牌的类
 * @notes: 
 * @Author: 本火山
 * @Date: 2024-03-26 17:31:35
 * @LastEditors: 本火山
 * @LastEditTime: 2024-03-26 17:34:06
 */

class ScorePanel {
    score: number = 0;
    level: number = 1;
    scoreEle: HTMLElement;
    levelEle: HTMLElement;

    // 设置变量限制等级
    maxLevel: number;
    // 设置一个变量表示多少分时升级
    upScore: number;

    constructor(maxLevel: number = 10, upScore: number = 10) {
        this.maxLevel = maxLevel;
        this.upScore = upScore;
        this.scoreEle = document.getElementById('score')!;
        this.levelEle = document.getElementById('level')!;
    }

    // 设置一个加分的方法
    addScore() {
        this.score++;
        this.scoreEle.innerHTML = this.score + '';
        // 判断分数是多少
        if (this.score % this.upScore === 0) {
            this.levelUp();
        }
    }

    // 等级提升
    levelUp() {
        if (this.level < this.maxLevel) {
            this.level++;
            this.levelEle.innerHTML = this.level + '';
        }
    }
}
export default ScorePanel;